package interviewClassic150;


import org.junit.Test;

import java.util.Arrays;

public class HIndex {
    //3 0 6 1 5 -> 0 1 3 5 6
    public int hIndex(int[] citations) {
        int n = citations.length;
        //先将数组排序
        Arrays.sort(citations);
        int res = 0;
        //遍历
        for (int i = 0; i < n; i++) {
            if (n - i > res && citations[i] >= n - i) res = n - i;
        }
        return res;
    }

    @Test
    public void test() {
//        int[] citations = {0,1,3,5,6};
        int[] citations = {100};
        int res = hIndex(citations);
        System.out.println(res);
    }
}
